package com.cheetah.start.common.plugin.log;

import cn.hutool.core.util.StrUtil;
import com.cheetah.start.system.log.domain.SysLog;
import com.cheetah.start.system.log.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author xjh
 * @create 2021/7/5
 **/
@Slf4j
@Component
public class LogFactory {
    @Autowired
    private SysLogService sysLogService;

    @Async
    public void record(SysLog sysLog) {
        log.info("日志:[{}]", sysLog);
        if (StrUtil.isNotBlank(sysLog.getRequestParam()) && sysLog.getRequestParam().length() > 255) {
            sysLog.setRequestParam(sysLog.getRequestParam().substring(0, 254));
        }
        boolean save = sysLogService.save(sysLog);
        log.info("日志保存结果:[{}]", save);
    }
}
